<template>
  <a-row :gutter="10" style="height: 100%;">
    <a-col :md="10" :sm="24" style="height: 100%;">
      <a-card :bordered="false" style="height: 100%; overflow: auto;">
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :sm="16">
              <a-form-item :label="$t('m.system.role.entity.roleName')">
                <a-input placeholder="" v-model="queryParam.roleName$lk"></a-input>
              </a-form-item>
            </a-col>
            <a-col :sm="8">
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">{{ $t('m.common.button.query') }}</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- table区域-begin -->
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
        :customRow="clickRow"
        :rowClassName="setRowClassName"
        >
      </a-table>
      </a-card>
    </a-col>
    <a-col :md="14" :sm="24" style="height: 100%;">
      <a-card :bordered="false" style="height: 100%; overflow: auto;">
      <RolePermissionModal ref="modalForm" :roleId="roleId" @ok="modalFormOk" :back="back"></RolePermissionModal>
      </a-card>
    </a-col>
  </a-row>
</template>

<script>

  import RolePermissionModal from './modules/RolePermissionModal'
  import { YcListMixin } from '@/mixins/YcListMixin'
  import YchConstant from "@/api/YchConstant";

  export default {
    name: 'RolePermissionList',
    mixins: [YcListMixin],
    components: {
      RolePermissionModal,
    },
    props: {
      back: String,
      portal: {
        type: String,
        default: '0'
      }
    },
    data() {
      return {
        right: false,
        roleId: '',
        queryParam: {
          back: this.back
        },
        columns: [
          {
            title: this.$t('m.system.role.entity.roleName'),
            align: 'center',
            dataIndex: 'roleName',
            width: 160,
          },
          {
            title: this.$t('m.system.role.entity.roleCode'),
            align: 'center',
            dataIndex: 'roleCode',
            width: 100,
          },
        ],
        url: {
          list: YchConstant.PREFIX_SYSTEM + '/role/list',
          delete: YchConstant.PREFIX_SYSTEM + '/role/delete',
          deleteBatch: YchConstant.PREFIX_SYSTEM + '/role/deleteBatch'
        },
        record:{},
      }
    },
    methods: {
      handlePerssion: function(roleId) {
        this.$refs.modalUserRole.show(roleId)
      },
      searchReset() {
        this.queryParam = {
          back: this.back
        }
        this.loadData(1)
      },
      handleOpen(record) {
        this.role = record
        this.right = true
      },
      hideUserList() {
        this.right = false
      },
      afterLoad() {
        this.hideUserList()
      },
      clickRow(record, index){
        return {
          on:{
            click:()=>{
              if(this.record.id !== record.id){
                this.roleId = record.id
                this.record = record;
              }
            }
          }
        }
      },
      setRowClassName(record){
        let cls = ''
        if(record.id==this.record.id){
          cls = 'clickRowStyl'
        }
        return cls
      },
    }
  }
</script>
<style lang="less" scoped>

</style>
